/**
 * A simple program that reads in a text file and creates Items with a name and price. 
 * These items are then put into a list to make a display of the restaurant menu.
 * 
 * @author Bryan Milicia
 */

import java.util.*;
import java.text.*;
import java.io.File;
import java.io.FileNotFoundException;


public class Menud {

	protected static Collection<Item> items = new ArrayList<Item>();
//*************************************************************************
	/**
	 * Using the scanner function and delimiter function a .txt file is read into the program.
	 * The first object read in is a string, followed by a double. The delimiter identifies commas
	 * and spaces as separators between objects.
	 */
	
	public static void load(String fileName){

		try {
			 File file = new File(fileName);
	         Scanner scanner = new Scanner(file);
	         scanner.useDelimiter(System.getProperty("line.separator")); 
	         while(scanner.hasNext())
	         {
	        	Scanner lineScanner = new Scanner(scanner.next());
	     	    lineScanner.useDelimiter("\\s*,\\s*");
	     	    String iTYPE = lineScanner.next();
	     	    String mName = lineScanner.next();
	     	    double price = lineScanner.nextDouble();
	     	    Item m = new Item(iTYPE, mName, price);
	     	    items.add(m);
	         }
	         scanner.close();
	     } catch (FileNotFoundException e) 
	     	{
	    	 	e.printStackTrace();
	     	}
	} //End Load
//*************************************************************************
	/**
	 * This function runs through the list of items and prints out the Menu.
	 */
	
	public static String getItem(int i)
	{
		//System.out.println("num "+i);
		Iterator iterate = items.iterator();
		Item temp=new Item("","",0.0);
		
		while(iterate.hasNext())
		{
			for(int j=-1;j<i;j++)
			temp = ((Item)iterate.next());
			return temp.getName();
			
		}
		
		return temp.getName();

	}
	
	public static void printMenuItems()
	{
		System.out.println("\n	Menu");
		System.out.println("-------------------------");
        DecimalFormat df = new DecimalFormat("0.00");
    	
        System.out.println("\n*************");
        System.out.println("* Appetizer *");
        System.out.println("*************");
        for(Item m : items){
			if(m.getiType().equals("Appetizer")){
				System.out.println(m.getName() + " " + df.format(m.getPrice()));
			}
        }
		
        System.out.println("\n**********");
        System.out.println("* Entree *");
        System.out.println("**********");
	    for(Item w : items){
	    	if(w.getiType().equals("Entree")){
	    		System.out.println(w.getName() + " " + df.format(w.getPrice()));
	    	}
	    }
	    
	    System.out.println("\n**********");
	    System.out.println("* Drinks *");
	    System.out.println("**********");
	    for(Item q : items){
	    	if(q.getiType().equals("Drinks")){
				System.out.println(q.getName() + " " + df.format(q.getPrice()));
			}
			//System.out.println(m.getiType() + " " + m.getName() + " " + df.format(m.getPrice()));
		}
		System.out.println();
	}
//*************************************************************************
//*************************************************************************
//*************************************************************************
//*************************************************************************
	/**
	 * Main program. Functions are called here
	 */

	
}
